import axios from "axios"; import Image from "next/image"; import Link from "next/link"; import { useEffect, useState } from "react"; import { Navbar } from "../../../components/shared/NavBar"; import MobileNav from "../../../components/shared/MobileNav"; import { GetServerSideProps } from "next"; type InfoNovelProps = { id: string; API: string; }; type NovelData = { image?: string; title?: string; Release?: string; Status?: string; Author?: string; description?: string; chapters?: { chapterId?: string; chapter?: string; release?: string; }[]; notFound?: boolean; }; export default function InfoNovel({ id, API }: InfoNovelProps) { const [data, setData] = useState(); const [loading, setLoading] = useState(true); useEffect(() => { async function fetchData() { setLoading(true); try { const { data } = await axios.get(`${API}/api/novel/info/` + id); setData(data); } catch (error) { setData({ notFound: true, }); } finally { setLoading(false); } } fetchData(); return () => { setData(undefined); }; }, [id]); return (
{data && (
{data?.image && ( coverImage )}

{data?.title}

Release: {data?.Release}

Status: {data?.Status}

Author: {data?.Author}

{data?.description}

)}
{data?.chapters?.map((chapter) => (

{chapter?.chapter}

{chapter?.release}

))}
); } export const getServerSideProps: GetServerSideProps = async ({ params }) => { const { id } = params || {}; const API = process.env.ID_API; return { props: { id, API, }, }; };